package ${package.Controller};

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
<#if swagger2>
import io.swagger.annotations.*;
</#if>
import com.david.IfaceAutoTest.entity.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 *${table.comment!} 控制层
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
<#if swagger2>
@Api(tags = "${table.name!}接口")
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    private final ${table.serviceName} ${table.serviceName?lower_case};

    @Autowired
    public GirlController( ${table.serviceName} ${table.serviceName?lower_case}) {
        this.${table.serviceName?lower_case} = ${table.serviceName?lower_case};
    }

    <#if restControllerStyle>
    @GetMapping("/list")
    </#if>
    <#if swagger2>
    @ApiOperation(value = "${table.comment}列表查询", notes = "list")
    </#if>
    public CommonResult<Object> list() {
        return CommonResult.success(${table.serviceName?lower_case}.list());
    }

    <#if restControllerStyle>
    @GetMapping("/get")
    </#if>
    <#if swagger2>
    @ApiOperation(value = "${table.comment}详情查询", notes = "get")
    </#if>
    public CommonResult<Object> get(Integer id) {
        return CommonResult.success(${table.serviceName?lower_case}.getById(id));
    }

    <#if restControllerStyle>
    @PostMapping("/save")
    </#if>
    <#if swagger2>
    @ApiOperation(value = "${table.comment}保存", notes = "save")
    </#if>
    public CommonResult<Object> save(${entity} ${entity?lower_case}) {
        return CommonResult.success(${table.serviceName?lower_case}.save(${entity?lower_case}));
    }

    <#if restControllerStyle>
    @DeleteMapping("/delete")
    </#if>
    <#if swagger2>
    @ApiOperation(value = "${table.comment}删除", notes = "delete")
    </#if>
    public CommonResult<Object> delete(Integer id) {
        ${table.serviceName?lower_case}.removeById(id);
        return CommonResult.success();
    }
}
</#if>